package element.synt;

import ast.AstItem;
import ast.Expression;
import element.base.Synt;

import java.util.List;

public class ConstInitVal extends Synt {
    @Override
    public AstItem toAst() {
        if (getNodes().size() == 1) {
            Exp exp = (Exp) getNodes().getFirst();
            return exp.toAst();
        } else {
            Expression expression = new Expression();
            expression.operator = Expression.OperatorType.OP_ARRAY_CONCAT;
            if (getNodes().size() == 2) {
                return expression;
            }

            int initCount = (getNodes().size() - 1) / 2;
            for (int i = 0; i < initCount; i++) {
                ConstInitVal initVal = (ConstInitVal) getNodes().get(2 * i + 1);
                expression.operands.add(initVal.toAst());
            }

            return expression;
        }
    }
}
